<template>
	<view>
		<view style="line-height:100rpx;font-size:40rpx;background:#fff;padding:0 30rpx;box-sizing: border-box;font-weight: bold;">
			充值银行卡
		</view>
		<form>
			<view class='addAddress'>
				<view class='list'>
					<view class='item acea-row row-between-wrapper' style="position:relative;border-top:none;">
						<view class='name'><em style="color:#f00;margin-right:10rpx;">*</em>银行卡号</view>
						<input type='text' placeholder='请输入银行卡号' @blur="cardNoBlur" v-model="bankInfo.bankCardNo"
							placeholder-class='placeholder'></input>
						<image :src="getBankData.bankico" v-if="getBankData.bankico" class="bankIcon"></image>	
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view class='name'><em style="color:#f00;margin-right:10rpx;">*</em>充值金额</view>
						<input type='number' placeholder='请输入充值金额' v-model="bankInfo.amount"
							placeholder-class='placeholder'></input>
					</view>
					<view class='item acea-row row-between-wrapper' style="position:relative">
						<view class='name'><em style="color:#f00;margin-right:10rpx;">*</em>验证码</view>
						<input type='text' placeholder='请输入验证码' v-model="bankInfo.verificationCode"
							placeholder-class='placeholder'></input>
						<view class="dxCodeBox" @click="saveFunc" v-if="isFirstDxCode">获取验证码</view>	
						<view class="dxCodeBox" style="color:#ccc;" v-else>
							<view v-if="dxCodeTime>0">剩余 {{dxCodeTime}}s</view>
							<view v-else style="color:#f00;" @click="getAgain">再次获取</view>
						</view>
					</view>
				</view>
				<button class='keepBnt bg-color' @click="submitFunc">充值</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		getAllBank,
		setModifyBankSubmit
	} from '@/api/directSelling.js'
	import {
		shop_ht,
	} from '@/config/app_member.js';
	export default {
		data() {
			return {
				bankInfo: {
					token: "",
					memberCode:"",
					memberType: 3,
					bankCardNo: null,
					amount: null
					//verificationCode:""
				},
				getbankno: {
				  token: "",
				  memberCode: "",
				  memberType: 3
				},
				getBankData:{
					token: "",
					memberCode: "",
					memberType: 3,
					bankCode: null,
					bankico:"",
				},
				postData: {
				  token: "",
				  memberCode: "",
				  memberType: 3,
				  verificationCode: null,
				  bizOrderNo: null
				},
				isFirstDxCode:true,
				dxCodeTime:60,
				dxCodeTimeFun:null,
				isCheckCode:false,
			};
		},
		mounted() {
			this.bankInfo.token = this.$w_md5.hex_md5_32Upper('tlClomeo' + uni.getStorageSync('userInfo')
				.memberCode);
			this.bankInfo.memberCode=uni.getStorageSync('userInfo').memberCode;
			//获取银行卡账号
			this.getbankno.token = this.$w_md5.hex_md5_32Upper('tlQueryBankCard' + uni.getStorageSync('userInfo')
				.memberCode);
			this.getbankno.memberCode=uni.getStorageSync('userInfo').memberCode;
			//获取银行卡图片信息
			this.getBankData.token = this.$w_md5.hex_md5_32Upper('tlGetBankType' + uni.getStorageSync('userInfo')
				.memberCode);
			this.getBankData.memberCode=uni.getStorageSync('userInfo').memberCode;
			//提交充值单
			this.postData.token =  this.$w_md5.hex_md5_32Upper('tlPayByBackSMS' + uni.getStorageSync('userInfo')
				.memberCode);
			this.postData.memberCode = uni.getStorageSync('userInfo').memberCode;
			this.tlQueryBankCard();
		},
		methods: {
			tlQueryBankCard(){
				uni.request({
					url: shop_ht + '/shop_ht/manage/tlQueryBankCard.do',
					method: "get",
					data: this.getbankno,
					success: (res) => {
						if(res.data.status==1){
							this.bankInfo.bankCardNo=res.data.bankCardNo;
							this.cardNoBlur();
						}else{
							this.bankInfo.bankCardNo="";
						}
					}
				})
			},
			cardNoBlur(e){
				console.log("测试测试");
				this.getBankData.bankCode=this.bankInfo.bankCardNo;
				if(this.bankInfo.bankCardNo){
					uni.request({
						url: shop_ht + '/shop_ht/manage/tlGetBankType.do',
						method: "get",
						data: this.getBankData,
						success: (res) => {
							if(res.data.status==1){
								this.getBankData.bankico=res.data.bankico;
								this.getBankData.bankname=res.data.bankname;
							}else{
								this.getBankData.bankico="";
								this.getBankData.bankname="";
							}
						}
					})
				}
			},
			saveFunc() {
				let that=this;
				if (!this.bankInfo.bankCardNo) {
					this.$util.Tips({
						title: '银行卡号不能为空！'
					});
					return;
				}
				if (!this.bankInfo.amount) {
					this.$util.Tips({
						title: '充值金额不能为空！'
					});
					return;
				} 
				const reg = /(^[0-9]{1,}$)|(^[0-9]{1,}[\.]{1}[0-9]{1,2}$)/
				if (!reg.test(String(this.bankInfo.amount))) {
					this.$util.Tips({
						title: "请填写数字，两位小数！"
					})	
					return;
				}
				uni.request({
					url: shop_ht + '/shop_ht/manage/tlClomeo.do',
					method: "get",
					data: this.bankInfo,
					success: (res) => {
						if(res.data.status==1){//可以进行校验码验证操作
							this.$util.Tips({
								title: '发送验证码成功！'
							});
							this.isCheckCode=true;
							this.postData.bizOrderNo = res.data.zdhtOrderNo
							this.setdxCodeTime();
						}else{
							this.$util.Tips({
								title: res.data.msg
							});
						}
					}
				})

			},
			setdxCodeTime(){
				this.isFirstDxCode=false;
				this.dxCodeTimeFun=setInterval(()=>{
					if(this.dxCodeTime>0){
						this.dxCodeTime=this.dxCodeTime-1;
					}else{
						clearInterval(this.dxCodeTimeFun);
					}
					this.$forceUpdate();
				},1000)
			},
			//再次获取
			getAgain(){
				this.dxCodeTime=60;
				this.saveFunc();
			},
			submitFunc(){
				let that=this;
				if(this.isCheckCode!==true){
					if (!this.bankInfo.bankCardNo) {
						this.$util.Tips({
							title: '银行卡号不能为空！'
						});
						return;
					}
					if (!this.bankInfo.amount) {
						this.$util.Tips({
							title: '银行预留手机不能为空！'
						});
						return;
					} 
					uni.request({
						url: shop_ht + '/shop_ht/manage/tlClomeo.do',
						method: "get",
						data: this.bankInfo,
						success: (res) => {
							if(res.data.status==1){//可以进行校验码验证操作
								this.$util.Tips({
									title: '发送验证码成功！'
								});
								this.postData.bizOrderNo = res.data.zdhtOrderNo;
								this.isCheckCode=true;
								this.setdxCodeTime();
							}else{
								this.$util.Tips({
									title: res.data.msg
								});
							}
						}
					})
				}else{
					if(!this.bankInfo.verificationCode){
						this.$util.Tips({
							title: '请填写验证码'
						});
						return;
					}
					this.postData.verificationCode=this.bankInfo.verificationCode;
					uni.request({
						url: shop_ht + '/shop_ht/manage/tlPayByBackSMS.do',
						method: "get",
						data: this.postData,
						success: (res) => {
							if(res.data.status==1){//可以进行校验码验证操作
								this.$util.Tips({
									title: '充值成功！'
								});
								setTimeout(()=>{
									uni.navigateTo({
										url: "/pages/electronicWallet/recharge/index"
									});
								},1000)
							}else{
								this.$util.Tips({
									title: res.data.msg
								});
							}
						}
					})
					
				}
				
			},
			getAge(iden) {
				let val = iden.length;
				let myDate = new Date();
				let month = myDate.getMonth() + 1;
				let day = myDate.getDate();
				let age = 0;

				if (val === 18) {
					age = myDate.getFullYear() - iden.substring(6, 10) - 1;

					if (iden.substring(10, 12) < month || iden.substring(10, 12) == month && iden.substring(12, 14) <= day)
						age++;

				}
				if (val === 15) {
					age = myDate.getFullYear() - iden.substring(6, 8) - 1901;

					if (iden.substring(8, 10) < month || iden.substring(8, 10) == month && iden.substring(10, 12) <= day)
						age++;
				}
				return age;
				//this.age = age;
			}
		}
	}
</script>

<style scoped lang="scss">
	.addAddress .list {
		background-color: #fff;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.addAddress .list .item {
		padding: 30rpx 0rpx;
		border-top: 1rpx solid #eee;
	}

	.addAddress .list .item .name {
		width: 210rpx;
		font-size: 30rpx;
		color: #333;
	}

	.addAddress .list .item .address {
		// width: 412rpx;
		flex: 1;
		margin-left: 20rpx;
	}

	.addAddress .list .item input {
		width: 470rpx;
		font-size: 30rpx;
		text-align: left;
	}

	.addAddress .list .item .placeholder {
		color: #ccc;
	}

	.addAddress .list .item picker {
		width: 410rpx;
		height: 42rpx;
	}

	.addAddress .list .item picker .picker {
		width: 350rpx;
		font-size: 30rpx;
		text-align: right;
	}

	.addAddress .list .item picker .iconfont {
		font-size: 43rpx;
	}

	.addAddress .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}

	.addAddress .default checkbox {
		margin-right: 15rpx;
	}

	.addAddress .keepBnt {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 50rpx auto;
		font-size: 32rpx;
		color: #fff;
	}

	.addAddress .wechatAddress {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 0 auto;
		font-size: 32rpx;
		color: #fe960f;
		border: 1px solid #fe960f;
	}

	.dxCodeBox {
		position: absolute;
		right: 10rpx;
		top: 30rpx;
		color: #f00;
		font-size: 28rpx;
	}

	.messageBox {
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
	}
	.bankIcon{
		position:absolute;
		right:0;
		top:30rpx;
		width:130rpx;
		height:40rpx;
	}
</style>
